<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="keywords" content="scclui框架">
    <meta name="description" content="scclui为轻量级的网站后台管理系统模版。">
    <title>首页</title>

    <link rel="stylesheet" href="../common/layui/css/layui.css">
    <link rel="stylesheet" href="../common/css/sccl.css">
</head>

<body class="login-bg">
<div class="login-box">
    <header>
        <h1>牛牛后台管理系统</h1>
    </header>
    <div class="login-main">
        <form action="/manage/login" class="layui-form" method="post">
            <input name="__RequestVerificationToken" type="hidden" value="">
            <div class="layui-form-item">
                <label class="login-icon">
                    <i class="layui-icon"></i>
                </label>
                <input type="text" name="userName" lay-verify="userName" autocomplete="off" placeholder="这里输入登录名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="login-icon">
                    <i class="layui-icon"></i>
                </label>
                <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="这里输入密码"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="pull-left login-remember">
                    <label>记住帐号？</label>

                    <input type="checkbox" name="rememberMe" value="true" lay-skin="switch" title="记住帐号">
                    <div class="layui-unselect layui-form-switch"><i></i></div>
                </div>
                <div class="pull-right">
                    <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="login">
                        <i class="layui-icon"></i> 登录
                    </button>
                </div>
                <div class="clear"></div>
            </div>
        </form>
    </div>
    <footer>
        <p>xuan © www.aspku.com</p>
    </footer>
</div>
<script type="text/html" id="code-temp">
    <div class="login-code-box">
        <input type="text" class="layui-input" id="code"/>
        <img id="valiCode" src="/manage/validatecode?v=636150612041789540" alt="验证码"/>
    </div>
</script>
<script src="../res/jQuery.js"></script>
<script src="../common/layui/layui.js"></script>
<script>

    window.onload = function (ev) {
        $.ajax({
            url: '/api/getUser',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            success: function (res) {
                if (res.data != null) {//已经登录
                    window.location.href = "/page/index.html";
                }
            }
        })
    }
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form();
        form.verify({
            userName: function (value) {
                if (value === '')
                    return '请输入用户名';
            },
            password: function (value) {
                if (value === '')
                    return '请输入密码';
            }
        });

        var errorCount = 0;

        $.fn.serializeObject = function(){
            var obj = {};
            $.each(this.serializeArray(), function(index){
                var v = this['value'];
                try{
                    var t = JSON.parse(v);
                    if(typeof(t) == 'object') {
                        v = t;
                    }
                }catch(e){}
                if(this['name'].indexOf('.') > -1) {
                    var n = this['name'].split('.');
                    if(!obj[n[0]]) {
                        obj[n[0]] = {};
                        obj[n[0]][n[1]] = v;
                    } else {
                        if(obj[n[0]] instanceof Array) {
                            if(obj[n[0]][obj[n[0]].length - 1][n[1]]) {
                                var o = {};
                                o[n[1]] = v;
                                obj[n[0]].push(o);
                            } else {
                                obj[n[0]][obj[n[0]].length -1][n[1]] = v;
                            }
                        } else {
                            if(obj[n[0]][n[1]]) {
                                var o = {};
                                o[n[1]] = v;
                                obj[n[0]] = [obj[n[0]], o];
                            } else {
                                obj[n[0]][n[1]] = v;
                            }
                        }
                    }
                } else {
                    if(obj[this['name']]) {
                        if(obj[this['name']] instanceof Array) {
                            obj[this['name']].push(v);
                        } else {
                            obj[this['name']] = [obj[this['name']], v];
                        }
                    } else {
                        obj[this['name']] = v;
                    }
                }
            });
            return obj;
        };

        form.on('submit(login)', function (data) {
            var param = $(data.form).serializeObject()
            console.log(param);
            console.log("点击登录");
            var data = {}
            data.userName = param.userName;
            data.password =  param.password;
            console.log(data);
            $.ajax({
                //url:'/tGame',
                url: '/session/login',
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    console.log(res);
                    if (res.isSuccess) {
                        window.location.href = "/page/index.html";
                    } else {//登录失败
                        layer.msg(res.msg);
                    }
                    //window.location.href = "/page/index.html";
                }
            })
            return false;
        });

    });

    /*function submit($,params){
        $.post('/manage/login',params , function (res) {
            if (!res.success) {
                if (res.data !== undefined)
                    errorCount = res.data.errorCount
                layer.msg(res.message,{icon:2});
            }else
            {
                layer.msg(res.message,{icon:1},function(index){
                    layer.close(index);
                    location.href='/manage';
                });
            }
        }, 'json');
    }*/
</script>
</body>
</html>
